﻿@model TranslatedCopy
@{
    var article = (Article)ViewData["Article"];
    Layout = "~/Views/Shared/_LayoutPartial.cshtml";
    ViewBag.ImageUrl = "~/content/images/edit_page_48x48.png";
    ViewBag.Title = Html.Global("RES_TRANSLATE") + ":" + article.Title;
    var culture = (System.Globalization.CultureInfo)ViewData["TargetCulture"];
    var format = ViewData.ContainsKey("Format") ? (TextFormats)ViewData["Format"] : (TextFormats)article.ContentFormat;
}
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <input name="LCID" type="hidden" value="@culture.LCID" />
    <table style="width: 100%" cellpadding="5" cellspacing="5">
        <tr>
            <td colspan="2">
                @Html.ValidationSummary()
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td style="white-space: nowrap; text-align: right;">
                @Html.Global("RES_TRANSLATE_TO"):
            </td>
            <td colspan="2">
                <img src="@Url.Content(string.Format("~/Content/Images/flags/{0}.gif", culture.Name))" alt="@culture.Name" />
                <span>@culture.DisplayName</span>
            </td>
        </tr>
        <tr>
            <td style="width: 80px; text-align: right;">
                @Html.Global("RES_TITLE"):
            </td>
            <td style="width: 300px;">
                @Ajax.DnaFor().TextBox(m => m.Title).Width(300).Value(Model != null ? Model.Title : article.Title).GetHtml()
            </td>
            <td>
                @Html.ValidationMessageFor(m => m.Title, "*")
            </td>
        </tr>
        <tr>
            <td style="vertical-align: top; text-align: right;">
                @Html.Global("RES_SUMMARY") :
            </td>
            <td>
                @Ajax.DnaFor().TextArea(m => m.Summary).Height(100).Width(300).Value(Model != null ? Model.Summary : article.Summary).GetHtml()
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td style="white-space:nowrap;">
                @Html.Global("publishing", "ContentFormat"):
            </td>
            <td colspan="2">
                <ul class="d-horizontal-list">
                    @if (format == TextFormats.WiKi)
                    {
                        <li>
                            @Html.ActionLink(Html.Global("publishing", "HtmlFormat"), "Translate", new { id = article.ID, lang = culture.Name, format = (int)TextFormats.Xhtml })
                        </li>
                        <li>
                            @Ajax.Dna().Link("javascript:void(0);").ImageIcons(Url.Content("~/Content/Images/ok.gif")).LocText("publishing", "WikiFormat").GetHtml()
                            <input type="hidden" value="2" name="TranslatedCopy.ContentFormat" />
                        </li>
                    }
                    else
                    { 
                        <li>
                            @Ajax.Dna().Link("javascript:void(0);").ImageIcons(Url.Content("~/Content/Images/ok.gif")).LocText("publishing", "HtmlFormat").GetHtml()
                        </li>
                        <li>
                            @Html.ActionLink(Html.Global("publishing", "WikiFormat"), "Translate", new { id = article.ID, lang = culture.Name, format = (int)TextFormats.WiKi })
                            <input type="hidden" value="1" name="TranslatedCopy.ContentFormat" />
                        </li>
                    }
                </ul>
            </td>
        </tr>
        <tr>
            <td colspan="3">
                @if (format == TextFormats.WiKi)
                {
                    <div>
                        @{
                    Ajax.Dna().RichTextBox("TranslatedCopy.Body")
                        .AllowHTMLEditing(false)
                        .Options(opts => { opts.Mode = "source"; })
                        .Resizable()
                        .Height(300)
                        .Value(Model != null ? Model.Body : article.Body)
                        .ToolPanes(panes =>
                        {
                            panes.Clear();
                            panes.Add().CustomTools(tb =>
                            {
                                tb.Add().AddCombo(combo =>
                                {
                                    combo.Items(items =>
                                    {
                                        items.AddValue(Html.Global("RES_QUOTE"), "((({0})))");
                                        items.AddValue(Html.Global("RES_HEAD") + " 1", "=={0}==");
                                        items.AddValue(Html.Global("RES_HEAD") + " 2", "==={0}===");
                                        items.AddValue(Html.Global("RES_HEAD") + " 3", "===={0}====");
                                        items.AddValue(Html.Global("RES_HEAD") + " 4", "====={0}====");
                                        items.AddValue(Html.Global("RES_HEAD") + " 5", "======{0}======");
                                    })
                                    .Options(opts =>
                                    {
                                        opts.OnItemSelected = "$wf(ui.value);";
                                    })
                                    .DropDownList();

                                })
                                .AddIcon("d-rte-icon d-rte-toc", "$wf(\"{toc}\");", "")
                                .AddIcon("d-rte-icon d-rte-bold", "$wf(\"'''{0}'''\");", "")
                                .AddIcon("d-rte-icon d-rte-italic", "$wf(\"''{0}''\");", "")
                                .AddIcon("d-rte-icon d-rte-underline", "$wf('__{0}__');", "")
                                .AddIcon("d-rte-icon d-rte-strikeThrough", "$wf('--{0}--');", "")
                                .AddSeparator()
                                .AddIcon("d-rte-icon d-rte-insertOrderedList", "$wf(\"#{0}\");", "")
                                .AddIcon("d-rte-icon d-rte-insertUnorderedList", "$wf(\"*{0}\");", "")
                                .AddSeparator()
                                .AddIcon("d-rte-icon d-rte-justifyLeft", "$wf('<{0}<');", "")
                                .AddIcon("d-rte-icon d-rte-justifyRight", "$wf('>{0}>');", "")
                                .AddSeparator()
                                .AddIcon("d-rte-icon d-rte-link", "$wf('[{0}|{0}]');", "")
                                .AddIcon("d-rte-icon d-rte-superscript", "$wf('^^{0}^^');", "")
                                .AddIcon("d-rte-icon d-rte-subscript", "$wf(',,{0},,');", "")
                                .AddIcon("d-rte-icon d-rte-img", "$dna.fileDlg(\"" + Url.Action("Dialog", "WebFiles", new { Area = "", website = WebSiteContext.Current.Web.Name }) + "\",null,function(_src){$wf('[image|{0}|'+_src+']');});", "")
                                .AddIcon("d-rte-icon d-rte-insertHorizontalRule", "$wf(\"----\");", "")
                                .AddIcon("d-rte-icon d-rte-insertCode", "$wf('<code html>{0}</code>');", "");
                            });
                        })
                        .Render();
                        }
                    </div>
                }
                else
                {
                    <div>
                        @{Ajax.Dna().RichTextBox("TranslatedCopy.Body")
                          .ToolPanes(panes =>
                          {
                              panes.Add().CustomTools(tool =>
                              {
                                  tool.Add().Buttons(buttons =>
                                  {
                                      buttons.AddIconButton("d-rte-icon d-rte-link", "$(\"#insertDlg\").dialog(\"open\");");
                                      buttons.AddIconButton("d-rte-icon d-rte-img", "$dna.fileDlg(\"" + Url.Action("Dialog", "WebFiles", new { Area = "", website = WebSiteContext.Current.Web.Name }) + "\",null,function(_src){ $(\"#TranslatedCopy_Body\").richtextbox(\"runCmd\",\"insertHTML\",\"<img src='\"+_src+\"' alt=''/>\");});");
                                      Ajax.Dna().Dialog(Html.Global("RES_INSERT_LINK"))
                                          .Name("insertDlg")
                                          .HtmlAttributes(new { style = "overflow:visible" })
                                          .Options(opts =>
                                          {
                                              opts.AutoOpen = false;
                                              opts.ShowModal = true;
                                              opts.IsResizable = false;
                                              opts.Position = new string[] { "center", "center" };
                                          })
                                          .Body(@<text>
                            <table>
                                <tr>
                                    <td>@Html.Global("publishing", "Url")
                                    </td>
                                    <td>@Ajax.Dna().TextBox("linkUrl").Value("http://").GetHtml()
                                    </td>
                                </tr>
                                <tr>
                                    <td>@Html.Global("RES_TEXT")
                                    </td>
                                    <td>@Ajax.Dna().TextBox("linkText").GetHtml()
                                    </td>
                                </tr>
                                <tr>
                                    <td>@Html.Global("RES_TOOLTIP")
                                    </td>
                                    <td>@Ajax.Dna().TextBox("linkTitle").GetHtml()
                                    </td>
                                </tr>
                                <tr>
                                    <td>@Html.Global("RES_TARGET")
                                    </td>
                                    <td>@(Ajax.Dna().ComboBox("linkTargets")
            .DropDownStyle(DropdownStyles.DropdownList)
            .Select("_self")
            .Bind(new string[] { "_self", "_blank", "_parent", "_top" })
            .GetHtml())
                                    </td>
                                </tr>
                            </table>
                            </text>)
                                 .Buttons(btns =>
                                 {
                                     btns.Add(Html.Global("RES_INSERT"), "$(this).dialog('close'); $(\"#TranslatedCopy_Body\").richtextbox(\"runCmd\",\"insertHTML\",\"<a src='\"+$('#linkUrl').val()+\"' target='' title='\"+$('#linkTitle').val()+\"' />\"+$('#linkText').val()+\"</a>\");");
                                     btns.AddClose().Text = Html.Global("RES_CLOSE");
                                 })
                                 .Render();
                                  });
                              });
                          })
                          .Height(400).Resizable()
                           .Value(Model != null ? Model.Body : article.Body)
                          .Render();}
                    </div>
                }
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <div style="padding: 10px; text-align: center;">
                    @Ajax.Dna().Button("btnSave").Submit().LocText("RES_SAVE").ImageIcons(Url.Content("~/content/images/icon_save.gif")).GetHtml()
                    @Ajax.Dna().Button("btnCancel").Click("location=\"" + Url.Action("Edit", "Article", new { id = article.ID, Area = "Publishing" }) + "\"").LocText("RES_CANCEL").ImageIcons(Url.Content("~/content/images/icon_back_16.png")).GetHtml()
                </div>
            </td>
        </tr>
    </table>
}
<script type="text/javascript">
    function $wf(_format) {
        $dna.insertFormat($("#TranslatedCopy_Body"), _format);
    }
</script>
